import ecenter from "../lib/node_modules/ecenter-core/dist/ecenter-core.es";

let router = null; //ecenter.router.create(config, import.meta.glob('./views/**/*.vue'));
const install = (app) => {
    if (install.installed) return;
    install.installed = true;
    const ecenterMUI = app.config.globalProperties.$ecenterMUI;
    /**
     * 若views 根目录下没有直接设置index.vue和login.vue则必须在路由表里配置首页和登录页，其他路由无需写
     * auth:是否需要权限控制
     * title:页面标题
     * */
    let _routers = ecenterMUI["ecm-routers"];
    const config = [
        {
            path: "/login",
            name: "login",
            component: ecenterMUI.EcmLogin,
            meta: {
                title: "登录",
            },
        },
        {
            path: "/",
            name: "index",
            component: () => import("./views/index.vue"),
            meta: {
                auth: true,
                title: "首页",
            },
        },
        {
            path: "/home",
            name: "home",
            component: () => import("./views/home/home.vue"),
            meta: {
                auth: true,
                title: "首页",
            },
        },
        {
            path: "/personal",
            name: "personal",
            component: () => import("./views/personal/personal.vue"),
            meta: {
                auth: true,
                title: "个人中心",
            },
        },
        {
            path: "/jnzx",
            name: "jnzx",
            component: () => import("./views/jnzx/jnzx.vue"),
            meta: {
                auth: true,
                title: "江南资讯",
            },
        },
        {
            path: "/zxxq",
            name: "zxxq",
            component: () => import("./views/realtime/zxxq.vue"),
            meta: {
                auth: true,
                title: "资讯详情",
            },
        },
        {
            path: "/wxlj",
            name: "wxlj",
            component: () => import("./views/wxlj/wxlj.vue"),
            meta: {
                auth: true,
                title: "我想了解",
            },
        },
        ..._routers,
    ];
    let base_url = location.pathname + location.search;
    router = ecenter.router.create(
        config,
        import.meta.globEager("./views/**/*.vue"),
        base_url
    );
    app.use(router);
    app.config.globalProperties.$router = router;
};

export default { install, router };
